﻿using System.CodeDom.Compiler;
using System.IO;
using System.Text;

namespace RazorEngine.Templating
{
    public static class TemplateCompilationExceptionExtension
    {
        public static StringBuilder WriteErrors(this TemplateCompilationException ex, StringBuilder writer)
        {
            foreach (CompilerError x in ex.Errors)
                writer.AppendFormat(
                    @"#{0},Msg:{1}
File:{2}
Location:[{3},{4}]
--------------------",
                    x.ErrorNumber, x.ErrorText, x.FileName, x.Column, x.Line);
            return writer;
        }

        public static void WriteErrors(this TemplateCompilationException ex, TextWriter writer)
        {
            foreach (CompilerError x in ex.Errors)
                writer.Write(string.Format(
                    @"#{0},Msg:{1}
File:{2}
Location:[{3},{4}]
--------------------",
                    x.ErrorNumber, x.ErrorText, x.FileName, x.Column, x.Line));
        }
    }
}